package com.emns.web.yuedu;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.emns.pojo.YueduComment;
import com.emns.service.yuedu.YueduCommentService;
import common.PageInfo;

@Controller
@RequestMapping(value = "/yueduComment")
public class YueduCommentController {

	@Autowired
	YueduCommentService ycs;

	// 查找所有悦读评论数据
	@RequestMapping(value = "/queryPage")
	public String queryPage(Model model,
			@RequestParam(required = true) Integer yueduId,
			@RequestParam(required = false) Integer pageNo,
			@RequestParam(required = false) String content,
			@RequestParam(required = false) String startDate,
			@RequestParam(required = false) String endDate) {
		System.out.println("niuniu:" + pageNo);
		PageInfo<YueduComment> pageInfo = new PageInfo<YueduComment>();
		if (pageNo == null) {
			pageNo = 1;
		}
		pageInfo.setPageNum(pageNo);
		ycs.queryPageAll(yueduId, content, startDate, endDate, pageInfo);
		model.addAttribute("info", pageInfo);
		model.addAttribute("content", content);
		model.addAttribute("startDate", startDate);
		model.addAttribute("endDate", endDate);
		model.addAttribute("yueduId", yueduId);
		return "/yuedu_comment_manager";
	}

	@RequestMapping(value = "/audit")
	public String auditComment(Model model, Integer[] commentId,
			@RequestParam(required = true) Integer yueduId,
			@RequestParam(required = false) Integer pageNo,
			@RequestParam(required = false) String content,
			@RequestParam(required = false) String startDate,
			@RequestParam(required = false) String endDate,
			@RequestParam(required = true) int passVal) {
		if (yueduId != null) {
			if (passVal == 0)
				ycs.audit(commentId, false);
			else
				ycs.audit(commentId, true);
		}
		return "forward:/yuedu_comment/queryPage";
	}

	@RequestMapping(value = "/delete")
	public String deleteComment(Model model, Integer[] commentId,
			@RequestParam(required = true) Integer yueduId,
			@RequestParam(required = false) Integer pageNo,
			@RequestParam(required = false) String content,
			@RequestParam(required = false) String startDate,
			@RequestParam(required = false) String endDate) {
		if (yueduId != null) {
			ycs.delete(commentId);
		} else {
			System.out.println("commentId is null");
		}
		return "forward:/yuedu_comment/queryPage";
	}

}
